import 'package:animal/network/api.dart';
import 'package:animal/socket/type_model.dart';
import 'package:animal/ui/friend/NWApi.dart';
import 'package:animal/ui/friend/model/search_user_model.dart';
import 'package:animal/ui/friend/page/friend_info_page.dart';
import 'package:animal/widgets/PageStateWidget.dart';
import 'package:flutter/cupertino.dart';
import 'package:flutter_smart_dialog/flutter_smart_dialog.dart';
import 'package:get/get.dart';

class AddFriendController extends GetxController {
  var pageState = PageState.none.obs;

  TextEditingController textEditingController = TextEditingController();

  var infoData = SearchUserModel().obs;

  ///搜索好友
  void searchUser({String type = "search", String? search = ""}) {
    //group|群聊，qr|扫一扫，businessCar|名片，search|搜索
    if (search!.isEmpty) {
      SmartDialog.showToast("搜索内容不能为空");
      return;
    }
    var putData = {
      "addType": type,
      "search": search,
    };
    SmartDialog.showLoading();
    HttpManager().get<SearchUserModel>(ChatApi.friendFind, queryParameters: putData).listen((value) {
      SmartDialog.dismiss();
      if (value.data != null) {
        infoData.value = value.data!;
        Get.to(FriendInfoPage(
            userModel: UserModel(
          id: infoData.value.id.toString(),
          nickName: infoData.value.nickName,
          account: infoData.value.account,
          head: infoData.value.headImg,
          isFriend: false,
          uid: infoData.value.uid,
          addType: "search",
          friendAddType: infoData.value.friendAddType,
        )));
      } else {
        SmartDialog.showToast("暂无搜索相关用户");
      }
    }, onError: (err) {
      SmartDialog.dismiss();
      debugPrint(err.message);
    });
  }
}
